package Test1;

import java.io.File;
import java.io.IOException;
import java.util.HashMap;
import java.util.Objects;

public class Streams {

    public static void main(String[] args) throws IOException {

//        extracted();
//        String path ="D:\\a";
//        File file = new File(path);
//        extracted1(file);

        File file1 = new File("F:\\IDEA\\wbk");



        HashMap<String,Integer> hashMap = new HashMap<>();
        getCount(hashMap,file1);
        System.out.println(hashMap);
    }

    private static void getCount(HashMap<String, Integer> hashMap, File file1) {
        File[] files = file1.listFiles();
        for (File file : Objects.requireNonNull(files)) {
            if (file.isFile()) {
                String f = file.getName();
                String[] split = f.split("\\.");
                if (split.length == 2) {
                    String name = split[1];
                    if (hashMap.containsKey(name)) {
                        int i = hashMap.get(name);
                        i++;
                        hashMap.put(name, i);
                    } else {
                        hashMap.put(name, 1);
                    }
                }
            } else {
                getCount(hashMap, file);
            }

        }
    }

    private static void extracted1(File src) {


        File[] files = src.listFiles();

        for (File file1 : files) {
             if(file1.isFile()){
                 file1.delete();
             }else{
                 extracted1(file1);
             }
        }

        src.delete();
    }

    private static void extracted() throws IOException {
        String path="wbk\\aaa";
        File file = new File(path);

        if(!file.exists()){
            file.mkdirs();

        }
        File file1 = new File(path,"a.txt");

        boolean newFile = file1.createNewFile();
        System.out.println(newFile);
    }
}

